import router from ".";
import { getToken } from "@/utils/token";
<<<<<<< HEAD
=======
import useStore from "@/store";
>>>>>>> resume

router.beforeEach((to, from, next) => {
    const token = getToken();
    if (!token) {
        if (to.name !== 'Login') {
            next({
                name: 'Login'
            });
        } else {
            next();
        }
    } else {
        if (to.name === 'Login') {
<<<<<<< HEAD
            next({
                name: 'Home'
            });
=======
            // 已登录用户访问登录页，根据角色跳转到对应页面
            const store = useStore();
            const userRole = store.app.role || 'user';
            let targetRoute = '/';
            
            if (userRole === 'enterprise') {
                targetRoute = '/frontend/enterprise-home';
            } else if (userRole === 'admin') {
                targetRoute = '/backend';
            } else {
                targetRoute = '/';
            }
            
            next(targetRoute);
>>>>>>> resume
        } else {
            next();
        }
    }
});